package com.lyu.xiaolvshu.auth.sms;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class AliyunSmsClientConfig {

    @Resource
    private AliyunAceessKeyProperties aliyunAceessKeyProperties;

    @Bean
    public Client smsClient() {
        Config config = new Config()
                .setAccessKeyId(aliyunAceessKeyProperties.getAccessKeyId())
                .setAccessKeySecret(aliyunAceessKeyProperties.getAccessKeySecret());
        config.setEndpoint(aliyunAceessKeyProperties.getEndpoint());
        try {
            return new Client(config);
        } catch (Exception e) {
            log.error("初始化阿里云短信客户端错误: ", e);
            return null;
        }
    }
}
